<template>
  <div class="bread">
    <ul class="fl sui-breadcrumb">
      <li>
        <a href="#">搜索结果</a>
      </li>
    </ul>
    <ul class="fl sui-tag">
      <!-- 通过三级列表展示的面包屑categoryName数据 -->
      <li class="with-x" v-if="categoryName">
        {{ categoryName }}<i @click="delCategoryName">×</i>
      </li>
      <!-- 通过搜索框关键词展示的面包屑keyword数据 -->
      <li class="with-x" v-if="keyword">
        {{ keyword }}<i @click="delKeyword">×</i>
      </li>
      <!-- 通过点击品牌栏展示的面包屑trademark数据 -->
      <li class="with-x" v-if="trademark">
        {{ trademark.split(":")[1] }}<i @click="delTrademark">×</i>
      </li>
      <!-- 通过点击attr属性展示的面包屑props数据 -->
      <li class="with-x" v-for="(attr, index) in props" :key="index">
        {{ attr.split(":")[1] }}<i @click="delProps(index)">×</i>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  name: "BreadCrumb",
  props: ["getSearchData", "searchParams"],
  computed: {
    //获取query中的categoryName数据
    categoryName() {
      return this.searchParams.categoryName;
    },
    //获取params中的keyword数据
    keyword() {
      return this.searchParams.keyword;
    },
    trademark() {
      return this.searchParams.trademark;
    },
    props() {
      return this.searchParams.props;
    },
  },
  methods: {
    //删除Query请求的数据
    delCategoryName() {
      this.$route.query.categoryId = undefined; //设置id为undefined
      this.$route.query.categoryName = undefined; //设置name为undefined
      this.getSearchData();
      //修改地址栏:自己跳自己Search,带着params的值进行跳转
      this.$router.push({ name: "Search", params: this.$route.params });
    },
    //删除Params请求的数据
    delKeyword() {
      this.$route.params.keyword = undefined; //清空搜索的params值，面包屑界面删除
      this.$eventBus.$emit("delKeyword"); //发射全局总线事件，清空首页搜索框内容
      this.getSearchData();
      //修改地址栏:自己跳自己Search,带着query的值进行跳转
      this.$router.push({ name: "Search", query: this.$route.query });
    },
    //发射delTrademark方法，删除点击属性选项
    delTrademark() {
      this.$emit("delTrademark");
    },
    //发射delProps方法，删除点击属性选项，
    delProps(index) {
      this.$emit("delProps", index);
    },
  },
};
</script>

<style scoped lang="less">
.bread {
  margin-bottom: 5px;
  overflow: hidden;
  .sui-breadcrumb {
    padding: 3px 15px;
    margin: 0;
    font-weight: 400;
    border-radius: 3px;
    float: left;
    li {
      display: inline-block;
      line-height: 18px;
      a {
        color: #666;
        text-decoration: none;
        &:hover {
          color: #4cb9fc;
        }
      }
    }
  }
  .sui-tag {
    margin-top: -5px;
    list-style: none;
    font-size: 0;
    line-height: 0;
    padding: 5px 0 0;
    margin-bottom: 18px;
    float: left;
    .with-x {
      font-size: 12px;
      margin: 0 5px 5px 0;
      display: inline-block;
      overflow: hidden;
      color: #000;
      background: #f7f7f7;
      padding: 0 7px;
      height: 20px;
      line-height: 20px;
      border: 1px solid #dedede;
      white-space: nowrap;
      transition: color 400ms;
      cursor: pointer;
      i {
        margin-left: 10px;
        cursor: pointer;
        font: 400 14px tahoma;
        display: inline-block;
        height: 100%;
        vertical-align: middle;
      }
      &:hover {
        color: #28a3ef;
      }
    }
  }
}
</style>